package com.example.service;

import com.example.entity.Clock;
import com.example.mapper.ClockMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

/**
*  打卡的逻辑层
**/
@Service
@RequiredArgsConstructor
public class ClockService {

   private final ClockMapper clockMapper;

   /**
   * 增
   **/
   public void add(Clock clock) {
       clockMapper.insert(clock);
   }

   /**
   * 删
   **/
   public void deleteById(Integer id) {
       clockMapper.deleteById(id);
   }

   /**
   * 批量删除
   **/
   public void deleteBatch(List<Integer> ids) {
       for (Integer id : ids) {
       clockMapper.deleteById(id);
       }
   }

   /**
   * 改
   **/
   public void updateById(Clock clock) {
       clockMapper.updateById(clock);
   }

   /**
   * 根据ID查询
   **/
   public Clock selectById(Integer id) {
       return clockMapper.selectById(id);
   }

   /**
   * 查询所有
   **/
   public List<Clock> selectAll(Clock clock) {
       return clockMapper.selectAll(clock);
   }

   /**
   * 分页查询
   **/
   public PageInfo<Clock> selectPage(Clock clock, Integer pageNum, Integer pageSize) {
       PageHelper.startPage(pageNum, pageSize);
       List<Clock> list = clockMapper.selectAll(clock);
       return PageInfo.of(list);
   }

    public List<Map<String,Object>> selectRank() {
        return clockMapper.selectRank();
    }
}